import { Application } from 'egg';
import { Model, Document, Schema } from './index.d';

export interface IMonitoringLog {
  message: string;
  detail: string;
  time?: string;
}

export const logSchemaConfig = {
  message: { type: String },
  detail: { type: String },
  time: { type: String },
};

export interface IApplicationOperationLogModel
  extends Document,
  IMonitoringLog { }
export default function operationLog(
  app: Application,
): Model<IApplicationOperationLogModel> {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;
  const OperationLogSchema: Schema = new Schema(logSchemaConfig, {
    timestamps: { updatedAt: 'updateTime', createdAt: 'createTime' },
  });
  return mongoose.model<IApplicationOperationLogModel>(
    'operation_log',
    OperationLogSchema,
  );
}
